import React from 'react'

import styles from '../../css/movie_item.scss'

import { Rate } from 'antd';

export default class MovieItem extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      rate: Math.floor(parseFloat(props.rate)/0.5/2)*0.5,
    }
  }

  render() {
    return <div className={styles.box} onClick={this.goDetail}>
      <img src={'https://images.weserv.nl/?url='+this.props.cover} className={styles.img}/>
      <ul className={styles.content}>
        <li>名称：{this.props.title}</li>
        <li>导演：{this.props.directors.join(' ')}</li>
        <li>主演：{this.props.casts.join(' ')}</li>
      </ul>
      <Rate allowHalf defaultValue={this.state.rate} />
    </div>
  }

  goDetail = () => {
    const type = window.location.hash.split('/')[2];
    this.props.history.push('/movie/detail/' + type + '/' + this.props.id)
  }
}